Add input token count to agent.tool.responseLength telemetry event #1197
+21
−16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The
agent.tool.responseLength
telemetry event was only reporting the size of tool outputs, missing crucial information about the size of tool inputs. This made it difficult to get a complete picture of token consumption and costs associated with tool invocations.Solution
Modified the
sendInvokedToolTelemetry
function to calculate and report both input and output token counts:toolInput
parameter to the function signature to accept the tool call input as a stringPromise.all
to efficiently calculate both:tokenCount
: Number of tokens in the tool response (output)inputTokenCount
: Number of tokens in the tool inputinputTokenCount
measurement fieldtoolCalling.tsx
: Passthis.props.toolCall.arguments
(already a JSON string)chatVariables.tsx
: Serialize the input object withJSON.stringify(input)
Example
When a tool is invoked with input like:
The telemetry event now includes:
toolName
: Name of the tool being invokedtokenCount
: Token count of the tool's responseinputTokenCount
: Token count of the tool's input (new)This provides complete visibility into token consumption for both sides of tool invocations, enabling better cost tracking and optimization.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
iojs.org
curl -q --fail --compressed -L -s REDACTED -o -
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.